<?php
/**
 * Created by IntelliJ IDEA.
 * User: ahwwl
 * Date: 2018/2/7
 * Time: 上午10:15
 */

namespace app\common;


use app\model\MobileMsg;

class MobileSMS
{
    static function sendMsg($mobile,$content)
    {
        $MobileMsg = new MobileMsg();
        $msgid = md5($mobile.NOW_TIME.rand());
        try{
            //        $url = "http://www.win10030.com/widget?type=noticeInfo&notice_type=101";
//        $sign=md5('comtemt='.$content.'&phone_num='.$mobile.'&source_from=UUBOX&key=uuboxllkj');
//        $data = [
//            "source_from"   =>  'UUBOX',
//            "phone_num"     =>  $mobile,
//            "comtemt"       =>  $content,
//            "sign"          =>  $sign
//        ];

            $data = [
                "account"       =>  'dh1793',
                "password"      =>  "b072d70b97249e8485536ef2fcd32bf5",
                "msgid"         =>  $msgid,
                "phones"        =>  $mobile,
                "content"       =>  $content,
                "sign"          =>  "【连连科技】"
            ];
            $query = $MobileMsg->sendMsg($msgid,$mobile,$content);
            if(!$query)
                exception("插入短信失败");
            $url = "http://www.dh3t.com/json/sms/Submit";
            $result = curl_url($url,['Content-Type: application/json; charset=UTF-8'],json_encode($data));
            if(!empty($result)&&$result["code"] == 200)
            {
                $body = json_decode($result["body"],true);
                if(!empty($body)&&$body["result"] == 0)
                {
                    $MobileMsg->msgStatus($msgid,1);
                    return true;
                }
            }
        }catch (\Exception $e)
        {

        }
        $MobileMsg->msgStatus($msgid,2);
        return false;
    }

    static function sendMobileCode($mobile,$code)
    {
        $content = "您的验证码为".$code."，本验证码有效期1小时，请勿告知他人，充值加油立享97折";
        if(!MobileSMS::sendMsg($mobile,$content))
        {
            return false;
        }
        return true;
    }
    static function sendMobileCardRecharge($mobile,$card_no,$basic_price)
    {
        $content = "尊敬的客户：您尾号".substr($card_no, -4)."的油卡于 ".date("Y-m-d H:i:s",NOW_TIME)." 成功充值".$basic_price."元,请前往加油站圈存后使用。感谢您的支持！";
        if(!MobileSMS::sendMsg($mobile,$content))
        {
            return false;
        }
        return true;
    }
    static function sendMobileDelivery($mobile,$express_name,$express_no)
    {
        $content = "尊敬的用户您好，您的加油卡已通过".$express_name."发送给您，快递单号为:".$express_no."。请留意查收，感谢您对我们的支持！";
        if(!MobileSMS::sendMsg($mobile,$content))
        {
            return false;
        }
        return true;
    }



}